package com.qo.qsdk.ui.base;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.TextView;

import com.qo.qsdk.utils.DynamicUtils;
import com.qo.qsdk.utils.Language;

public class FloatIconView implements IBaseView{

    private Activity mActivity;
    private LayoutInflater mInflater;
    private View mMain;
    public View mLogo, mPay, mCustomer, mClose;
    private TextView mPayT, mCustomerT, mCloseT;
    public boolean isOpen;

    public FloatIconView(Activity mActivity) {
        this.mActivity = mActivity;
        this.mInflater = LayoutInflater.from(mActivity);
        this.mMain = this.mInflater.inflate(DynamicUtils.layout(mActivity, "qsdk_f_r"), null);
        init(mMain);
    }

    public View getMain() {
        return mMain;
    }

    private void init(View v) {
        mPay = v.findViewById(DynamicUtils.id(mActivity, "pay"));
        mLogo = v.findViewById(DynamicUtils.id(mActivity, "logo"));
        mCustomer = v.findViewById(DynamicUtils.id(mActivity, "customer"));
        mClose = v.findViewById(DynamicUtils.id(mActivity, "close"));
        mPayT = v.findViewById(DynamicUtils.id(mActivity, "payT"));
        mCustomerT = v.findViewById(DynamicUtils.id(mActivity, "customerT"));
        mCloseT = v.findViewById(DynamicUtils.id(mActivity, "closeT"));
        isOpen = false;

        mPay = v.findViewById(DynamicUtils.id(mActivity, "pay"));
        mLogo = v.findViewById(DynamicUtils.id(mActivity, "logo"));
        mCustomer = v.findViewById(DynamicUtils.id(mActivity, "customer"));
        mClose = v.findViewById(DynamicUtils.id(mActivity, "close"));
        mPayT = v.findViewById(DynamicUtils.id(mActivity, "payT"));
        mCustomerT = v.findViewById(DynamicUtils.id(mActivity, "customerT"));
        mCloseT = v.findViewById(DynamicUtils.id(mActivity, "closeT"));
        isOpen = false;


        refresh();
        openMenu(mActivity);
    }

    public void refresh() {
        mPayT.setText(Language.Float_Pay.toString());
        mCustomerT.setText(Language.Float_Customer.toString());
        mCloseT.setText(Language.Float_Hide.toString());
    }

    @Override
    public void show(Activity activity) {
        refresh();
    }

    public void toggleMenu(Activity activity) {
        if (isOpen) closeMenu(activity);
        else openMenu(activity);
    }

    public void openMenu(Activity activity) {
        show(activity, true, true, true);
        isOpen = true;
    }

    public void closeMenu(Activity activity) {
        show(activity, false, false, false);
        isOpen = false;
    }

    public void show(Activity activity, boolean pay, boolean customer, boolean close) {
        mPay.setVisibility(pay ? View.VISIBLE : View.GONE);
        mCustomer.setVisibility(customer ? View.VISIBLE : View.GONE);
        mClose.setVisibility(close ? View.VISIBLE : View.GONE);
    }

    @Override
    public void hide(Activity activity) {

    }
}
